package cn.doubly.Controller;

import cn.doubly.Service.ChatService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.websocket.Session;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Controller
@CrossOrigin
public class UrlController {

    private static Logger log = LoggerFactory.getLogger(UrlController.class);

    @RequestMapping(value = "/",method = RequestMethod.GET)
    public String toIndex(){
        return "/index";
    }

    @RequestMapping(value = "/getOnlineUser",method = RequestMethod.POST)
    @ResponseBody
    public List<String> getOnlineUser(){
        log.info("获取所有在线用户");
        List<String> onLinUser = new ArrayList<>();
        for (Map.Entry<Session, String> sessionStringEntry : ChatService.onlineSessions.entrySet()) {
            onLinUser.add(sessionStringEntry.getValue());
        }
        return onLinUser;
    }

}
